{{extend("./layout.html")}}

{{#block ("body")}}
<div class="panel panel-default">
    <div class="panel-heading">
        <ol class="breadcrumb">
            <li><a href="#">首页</a></li>
            <li><a href="#">学生管理</a></li>
            <li class="active">学生列表</li>
        </ol>
    </div>
    <div class="panel-heading">
        <div class="input-group">
            <span class="input-group-addon" id="basic-addon1">学生姓名</span>
            <input type="text" class="form-control" id="studentName" placeholder="请输入学生姓名进行查询" value="{{keyword}}" aria-describedby="basic-addon1" style="width:200px;margin-right:10px;">
            <input type="button" class="btn btn-success" onclick="search()" value="查找" style="margin-right:10px;">
            <input type="button" class="btn btn-success" value="新增" onclick="window.location='/studentmanager/add'">
        </div>
    </div>
    <div class="panel-body">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>手机号码</th>
                <th>地址</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
               {{#each(studentList)}}
                   <tr>
                       <td>{{this.name}}</td>
                       <td>{{this.age}}</td>
                       <td>{{this.sex}}</td>
                       <td>{{this.phone}}</td>
                       <td>{{this.address}}</td>
                       <td>
                           <a href="javascript:window.location='/studentmanager/edit/{{this._id}}'" class ="btn btn-success" >编辑</a> |

                           <input type="button"  class ="btn btn-danger"  onclick="deleteStudent('{{this._id}}')" value="删除">
                       </td>
                   </tr>
                {{/each}}
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    function deleteStudent(id){
       if(confirm("确定删除该条数据吗？")){
           $.getJSON({
               url:"/studentmanager/delete/"+id,
               success:function(data){
                   //alert(data.message);
                   window.location="/studentmanager/list"
               },
               error:function(error){
                   console.log(error);
               }
           })
       }
    }


    function search() {
        var keywords=$("#studentName").val()
        window.location="/studentmanager/list?keyword="+keywords;

    }
</script>
{{/block}}
